/**
 * 
 */
package com.thor.palmmall.rest.product.converter;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.common.AOperateInfoConverter;
import com.thor.palmmall.rest.product.AProductChange;
import com.thor.palmmall.spi.product.SProductChange;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class AProductChangeConverter implements Converter<SProductChange, AProductChange> {

  public static AProductChangeConverter getInstance() {
    if (instance == null)
      instance = new AProductChangeConverter();
    return instance;
  }

  private static AProductChangeConverter instance;

  private AProductChangeConverter() {
  }

  @Override
  public AProductChange convert(SProductChange source) {
    if (source == null) {
      return null;
    }
    AProductChange target = new AProductChange();
    target.setUuid(source.getUuid());
    target.setVersion(source.getVersion());
    target.setVersionTime(source.getVersionTime());
    target.setCreateInfo(AOperateInfoConverter.getInstance().convert(source.getCreateInfo()));
    target
        .setLastModifyInfo(AOperateInfoConverter.getInstance().convert(source.getLastModifyInfo()));
    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    target.setBillNumber(source.getBillNumber());
    target.setBizState(source.getBizState());
    target.setBpmInstance(source.getBpmInstance());
    target.setBpmMessage(source.getBpmMessage());
    target.setBpmOutgoingState(source.getBpmOutgoingState());
    target.setBpmState(source.getBpmState());
    target.setAbortMsg(source.getAbortMsg());
    target.setStore(UCN.newInstance(source.getStore()));
    target.setContract(UCN.newInstance(source.getContract()));
    target.setTenant(UCN.newInstance(source.getTenant()));
    target.setPrintPriceTag(source.isPrintPriceTag());
    target.setPrintQty(source.getPrintQty());
    target.setRemark(source.getRemark());
    target.setProducts(
        ConverterUtil.convert(source.getProducts(), AProductChangeLineConverter.getInstance()));

    return target;
  }
}
